package com.zf.yichat.controller.balance;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
import com.github.pagehelper.PageHelper;
import com.zf.yichat.controller.BaseController;
import com.zf.yichat.dto.BalanceDetailCountDto;
import com.zf.yichat.dto.RechargeRecordDto;
import com.zf.yichat.dto.UserWithdrawDto;
import com.zf.yichat.dto.response.BalanceDetailCountDto2;
import com.zf.yichat.dto.response.BalanceUserDto;
import com.zf.yichat.dto.response.UserWithdrawExcelDto;
import com.zf.yichat.mapper.*;
import com.zf.yichat.model.*;
import com.zf.yichat.service.*;
import com.zf.yichat.service.config.RedisService;
import com.zf.yichat.service.dto.BalanceListDto;
import com.zf.yichat.utils.common.DateUtils;
import com.zf.yichat.utils.common.DtoChangeUtils;
import com.zf.yichat.utils.common.FsConst;
import com.zf.yichat.utils.response.FsResponse;
import com.zf.yichat.utils.response.FsResponseGen;
import com.zf.yichat.vo.BalanceType;
import com.zf.yichat.vo.DictKey;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

/**
 * 一句话描述功能
 *
 * @author fengsong
 * @date create in 10:35 2019/7/30 2019
 */
@Controller
@RequestMapping("balance")
@Slf4j
public class BalanceController extends BaseController {

    @Autowired
    private UserWithdrawMapper userWithdrawMapper;

    @Autowired
    private PacketService packetService;

    @Resource
    private UserBalanceDetailMapper userBalanceDetailMapper;

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private BalanceService balanceService;

    @Autowired
    private UserBankMapper userBankMapper;

    @Autowired
    private UserBankXsMapper userBankXsMapper;

    @Resource
    private UserBalanceMapper userBalanceMapper;

    @Autowired
    private PayService payService;

    @Autowired
    private SysDictService sysDictService;

    @Autowired
    private UserWithdrawService userWithdrawService;

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private UserService userService;

    @Value("${st.path.upload}")
    private String excelPath;

    /**
     * 提现审核页面
     * @return
     */
    @RequestMapping("withdraw/index")
    public String withdrawIndex() {
        //新生余额
//        getRequest().setAttribute("xsBalance", redisService.getVal("xs_balance"));
//        //汇聚余额
//        getRequest().setAttribute("hjBalance", redisService.getVal("hj_balance"));
        // 当日已审批的提现金额总和
        Integer currWithdrawMoney = userWithdrawMapper.queryCurrWithdrawMoney();
        if (null == currWithdrawMoney) {
            currWithdrawMoney = 0;
        }
        getRequest().setAttribute("currWithdrawMoney", currWithdrawMoney);
        return "balance/index";
    }

    /**
     * 提现审核页面
     * @param page
     * @param limit
     * @param status 审核状态
     * @param userId
     * @return
     */
    @RequestMapping("withdraw/list")
    @ResponseBody
    public FsResponse withdrawList(Integer page, Integer limit, Integer status, Long userId,
                                   String checkTime, String recommendCode) {

        Example example = new Example(UserWithdraw.class);
        Example.Criteria criteria = example.createCriteria();
        if (null != status) {
            if (1 == status) {
                criteria.andCondition("(status = 1 or status = 3)");
            }else {
                criteria.andEqualTo("status", status);
            }
        }
        if (null != userId) {
            criteria.andEqualTo("userId", userId);
        }
        if (StringUtils.isNotBlank(checkTime)) {
            criteria.andCondition("DATE_FORMAT(check_time,'%Y-%m-%d') = ", checkTime);
        }
        // 根据创建时间倒序排列
        example.setOrderByClause("ctime desc");


        // 根据邀请码查询
        if (StringUtils.isNotBlank(recommendCode)) {
            criteria.andLike("parentCode", "%" + recommendCode + "%");
        }

        PageHelper.startPage(page, limit);
        List<UserWithdraw> withdrawList = userWithdrawMapper.selectByExample(example);
        return DtoChangeUtils.getPageList(withdrawList, copy -> {
            UserWithdrawDto userWithdraw = new UserWithdrawDto();
            BeanUtils.copyProperties(copy, userWithdraw);
            String rate=Optional.ofNullable(sysDictService.selectOne(DictKey.sys_withdraw_rate)).map(SysDict::getValue).orElse("0");
            BigDecimal money = copy.getMoney();
            if (null != money) {
                money =  money.multiply(new BigDecimal("1").subtract(new BigDecimal(rate).divide(new BigDecimal("100"))));
                userWithdraw.setMoney(money);
            }
            Long uId = copy.getUserId();
            User user = userMapper.queryUserByParam(null, uId);
            if (null != user) {
                userWithdraw.setUserRemark(user.getRemark());
            }
            return userWithdraw;
        });

    }

    @RequestMapping("recharge/index")
    public String rechargeIndex() {
        return "balance/recharge";
    }

    @RequestMapping("platform")
    public String platformBalance(Integer type) {
        getRequest().setAttribute("type", type);
        return "balance/platform";
    }

    @Autowired
    private RedisService redisService;

    @RequestMapping("platform/set")
    @ResponseBody
    public FsResponse platformBalanceSet(Integer type, BigDecimal money) {
        if (type == 0) {
            redisService.setVal("hj_balance", money.toString());
        } else {
            redisService.setVal("xs_balance", money.toString());
        }
        return FsResponseGen.success();
    }

    @RequestMapping("recharge/list")
    @ResponseBody
    public FsResponse rechargeList(Integer page, Integer limit, Long userId) {
        Example example = new Example(UserBalanceDetail.class);
        Example.Criteria criteria = example.createCriteria();
        if (Objects.nonNull(userId)) {
            criteria.andEqualTo("userId", userId);
        }
        criteria.andEqualTo("type", 0);
        example.setOrderByClause(" ctime desc");
        PageHelper.startPage(page, limit);
        return DtoChangeUtils.getPageList(userBalanceDetailMapper.selectByExample(example), copy -> {
            UserWithdrawDto dto = new UserWithdrawDto();
            dto.setNick(userMapper.selectByPrimaryKey(copy.getUserId()).getNick());
            dto.setId(copy.getId().intValue());
            dto.setUserId(copy.getUserId());
            dto.setMemo(copy.getMemo());
            dto.setMoney(copy.getMoney());
            dto.setCtime(copy.getCtime());
            return dto;
        });
    }

    //暂时根据银行卡号关联查询下审核信息
    private UserBank selectBank(String bankNumber) {
        Example example = new Example(UserBank.class);
        example.createCriteria().andEqualTo("bankNumber", bankNumber);
        example.setOrderByClause(" id desc limit 1");

        return Optional.ofNullable(userBankMapper.selectOneByExample(example)).orElse(new UserBank());
    }

    private UserBankXs selectBankXs(String bankNumber) {
        Example example = new Example(UserBankXs.class);
        example.createCriteria().andEqualTo("bankNumber", bankNumber);
        example.setOrderByClause(" id desc limit 1");

        return Optional.ofNullable(userBankXsMapper.selectOneByExample(example)).orElse(new UserBankXs());
    }

    /**
     * 财务管理-提现审核功能
     * @param id
     * @param status
     * @param reason
     * @return
     */
    @ResponseBody
    @RequestMapping("withdraw/check")
    public synchronized FsResponse withdrawCheck(Integer id, Integer status, String reason) {
        return balanceService.checkWithdraw(id, status, reason);
    }


    //充值
    @ResponseBody
    @RequestMapping("deposit")
    public FsResponse deposit(Long userId, BigDecimal money) {
        if (!(boolean) getRequest().getSession().getAttribute("isOperate")) {
            return FsResponseGen.failMsg("无权限操作");
        }
//        if (!(boolean) getRequest().getSession().getAttribute("isAdmin0")) {
//            return FsResponseGen.failMsg("该功能已废弃");
//        }

        balanceService.update(userId, BalanceType.BACK_ADD, money, userId, "系统充值");
        return FsResponseGen.success();
    }

    /**
     * 查询系统充值记录
     * @param userId
     * @return
     */
    @ResponseBody
    @RequestMapping("rechargeRecord")
    public FsResponse rechargeRecord(Integer page, Integer limit, Long userId, String type) {

        Example example = new Example(UserBalanceDetail.class);
        Example.Criteria criteria = example.createCriteria();
        if (Objects.nonNull(userId)) {
            criteria.andEqualTo("userId", userId);
        }
        if (StringUtils.isNotBlank(type)) {
            criteria.andEqualTo("type", type);
        }

        example.setOrderByClause("ctime desc");
        PageHelper.startPage(page, limit);
        return DtoChangeUtils.getPageList(userBalanceDetailMapper.selectByExample(example), v -> {
            RechargeRecordDto dto = new RechargeRecordDto();
            dto.setCtime(v.getCtime());
            dto.setMoney(v.getMoney());
            dto.setType(v.getType());

            Long vUserId = v.getUserId();
            User user = userService.selectById(vUserId);
            dto.setUserId(vUserId);
            dto.setNick(user.getNick());
            return dto;
        });
    }


    //充值
    @ResponseBody
    //@RequestMapping("deposit/linshi")
    public FsResponse depositLinshi(Long userId, BigDecimal money) {
        balanceService.update(userId, BalanceType.BACK_ADD, money, userId, "系统充值");
        return FsResponseGen.success();
    }


    //提现
    @ResponseBody
    @RequestMapping("withdraw")
    public FsResponse withdraw(Long userId, BigDecimal money) {
//        if (!(boolean) getRequest().getSession().getAttribute("isAdmin0")) {
//            return FsResponseGen.failMsg("该功能已废弃");
//        }

        balanceService.update(userId, BalanceType.BACK_WITHDRAW, money, userId, "系统提现");
        return FsResponseGen.success();
    }


    @RequestMapping("user/index")
    public String userIndex() {
        BigDecimal totalBalance = userBalanceMapper.sumTotal();
        getRequest().setAttribute("totalBalance", totalBalance);


        return "balance/user";
    }

    @RequestMapping("balance/index")
    public String banalceIndex() {
        return "balance/balance";
    }

    /**
     * 后台充值详情
     * @return
     */
    @RequestMapping("balance/record")
    public String balanceRecord() {
        return "balance/record";
    }

    /**
     * 提现充值列表
     * @param page
     * @param limit
     * @param name
     * @param userId
     * @param mobile
     * @param ucode
     * @return
     */
    @RequestMapping("user/list")
    @ResponseBody
    public FsResponse userList(Integer page, Integer limit, String name,
                               String remark, Long userId, String mobile,
                               String ucode) {

        Example example = new Example(User.class);
        Example.Criteria criteria = example.createCriteria().andEqualTo("status", 0);
        if (StringUtils.isNotBlank(name)) {
            criteria.andLike("nick", "%" + name + "%");
        }
        if (StringUtils.isNotBlank(mobile)) {
            criteria.andLike("mobile", "%" + mobile + "%");
        }
        if (StringUtils.isNotBlank(remark)) {
            criteria.andLike("remark", "%" + remark + "%");
        }
        if (StringUtils.isNotBlank(ucode)) {
            criteria.andEqualTo("appid", ucode);
        }
        if (Objects.nonNull(userId)) {
            criteria.andEqualTo("id", userId);
        }
        example.setOrderByClause(" id desc");
        PageHelper.startPage(page, limit);
        return DtoChangeUtils.getPageList(userMapper.selectByExample(example), copy -> {
            BalanceUserDto dto = new BalanceUserDto();

            User user = userMapper.selectByPrimaryKey(copy.getId());
            dto.setNick(user.getNick());
            dto.setUserId(copy.getId());
            dto.setAvatar(copy.getAvatar());
            dto.setMobile(copy.getMobile());
            dto.setAppId(copy.getAppid());
            dto.setCtime(copy.getCtime());
            dto.setRemark(copy.getRemark());
            dto.setBalance(balanceService.selectByUserId(copy.getId()).getIncomeBalance());

            return dto;
        });
    }

    @RequestMapping("user/balance/count")
    @ResponseBody
    public synchronized FsResponse userBalanceCount(String startTime, String endTime) {
        BalanceDetailCountDto2 dto2 = new BalanceDetailCountDto2();

        FsResponse response = payService.xspayGetAccount();
        if (response.isSuccess()) {
            Map xsMap = (Map) response.getData();
            dto2.setXsAvailableBalance(new BigDecimal(String.valueOf(xsMap.get("availableBalance"))));
            dto2.setXsUnsettleBalance(new BigDecimal(String.valueOf(xsMap.get("unsettleBalance"))));
        }

        Pair<Long, BigDecimal> pair = balanceService.sumUserBalance();
        BigDecimal incomeBalanceUser = pair.getRight();
        Long detailId = pair.getLeft();

        BigDecimal recharge = new BigDecimal("3535347.34");
        BigDecimal withdrawApply = new BigDecimal("2717684.07");
        BigDecimal withdrawSuccess = new BigDecimal("2594461.82");
        BigDecimal withdrawFail = new BigDecimal("118699.25");
        BigDecimal packetSend = new BigDecimal("347888046.64");
        BigDecimal packetReceive = new BigDecimal("346944951.89");
        BigDecimal packetBack = new BigDecimal("894811.06");
        BigDecimal rechargeAdmin = new BigDecimal("-11265.12");
        BigDecimal withdrawAdmin = new BigDecimal("-1395.00");
        BigDecimal vipPacket = new BigDecimal("0.00");
        BigDecimal withdrawOffline = new BigDecimal("5271.76");

        //上面数据<= 12343752  2021-11-03 00:00:00，下面数据>12343752 <=detailId
        List<BalanceDetailCountDto> dtos = userBalanceDetailMapper.sumTotalGroupByType(12343752l, detailId);
        Map<Integer, BigDecimal> detailMap = new HashMap();
        for (BalanceDetailCountDto dto : dtos) {
            detailMap.put(dto.getType(), dto.getTotalMoney());
        }

        //充值多少钱
        recharge = recharge.add(Optional.ofNullable(detailMap.get(0)).orElse(BigDecimal.ZERO));
        //提现申请多少钱
        withdrawApply = withdrawApply.add(Optional.ofNullable(detailMap.get(12)).orElse(BigDecimal.ZERO));
        //提现成功多少钱
        withdrawSuccess = withdrawSuccess.add(Optional.ofNullable(detailMap.get(1)).orElse(BigDecimal.ZERO));
        //提现失败多少钱
        withdrawFail = withdrawFail.add(Optional.ofNullable(detailMap.get(13)).orElse(BigDecimal.ZERO));
        //发红包多少
        packetSend = packetSend.add(Optional.ofNullable(detailMap.get(2)).orElse(BigDecimal.ZERO));
        //领取多少
        packetReceive = packetReceive.add(Optional.ofNullable(detailMap.get(3)).orElse(BigDecimal.ZERO));
        //退回多少
        packetBack = packetBack.add(Optional.ofNullable(detailMap.get(5)).orElse(BigDecimal.ZERO));
        //系统充值
        rechargeAdmin = rechargeAdmin.add(Optional.ofNullable(detailMap.get(7)).orElse(BigDecimal.ZERO));
        //系统提现
        withdrawAdmin = withdrawAdmin.add(Optional.ofNullable(detailMap.get(8)).orElse(BigDecimal.ZERO));
        //视频红包
        vipPacket = vipPacket.add(Optional.ofNullable(detailMap.get(33)).orElse(BigDecimal.ZERO));
        //线下转账
        withdrawOffline = withdrawOffline.add(Optional.ofNullable(detailMap.get(40)).orElse(BigDecimal.ZERO));

        BigDecimal totalBalanceFlow = recharge.add(vipPacket).add(rechargeAdmin).subtract(withdrawSuccess).subtract(withdrawAdmin).subtract(withdrawOffline);
        BigDecimal waitWithDraw = withdrawApply.subtract(withdrawSuccess).subtract(withdrawFail);
        BigDecimal waitBack = packetSend.subtract(packetReceive).subtract(packetBack);
        BigDecimal incomeBalanceFlow = totalBalanceFlow.subtract(waitWithDraw).subtract(waitBack);
        BigDecimal incomeBalanceBad = incomeBalanceFlow.subtract(incomeBalanceUser);

        dto2.setIncomeBalanceFlow(incomeBalanceFlow);
        dto2.setIncomeBalanceBad(incomeBalanceBad);
        dto2.setIncomeBalanceUser(incomeBalanceUser);
        dto2.setTotalBalanceFlow(totalBalanceFlow);
        if (Objects.nonNull(dto2.getXsAvailableBalance())) {
            dto2.setXsBalanceBad(totalBalanceFlow.subtract(dto2.getXsAvailableBalance()).subtract(dto2.getXsUnsettleBalance()));
        }
//        dto.setStartTime(startTime);
//        dto.setEndTime(endTime);

        dto2.setDetailId(detailId);

        StringBuilder detailSb = new StringBuilder();
        detailSb.append("充值:").append(recharge).append(" 提现申请:").append(withdrawApply).
                append(" 提现成功:").append(withdrawSuccess).append(" 提现失败:").append(withdrawFail).
                append(" 发红包:").append(packetSend).append(" 领取:").append(packetReceive).append(" 退回").append(packetBack)
                .append(" 系统充值").append(rechargeAdmin).append(" 系统提现").append(withdrawAdmin).append(" 线下转账").append(withdrawOffline)
                .append(" 视频红包").append(vipPacket);
        dto2.setDetailBalance(detailSb.toString());

        ArrayList list = new ArrayList();
        list.add(dto2);
        return DtoChangeUtils.getPageList(list, v -> v);
    }

    /**
     * 用户资金明细页面
     * @param userId
     * @return
     */
    @RequestMapping("detail/index")
    public String detailIndex(Long userId) {
        User user = userMapper.selectByPrimaryKey(userId);
        getRequest().setAttribute("user", user);
        return "balance/list";
    }

    /**
     * 用户余额明细
     * type 0 支出  1 收入
     */
    @RequestMapping("detail/list")
    @ResponseBody
    public FsResponse balanceDetailList(Integer page, Integer limit, Integer type, Long userId, String ctime) {
        PageHelper.startPage(page, limit);
        FsResponse response = balanceService.selectList(type, userId, ctime);
//        if (response.isSuccess()) {
//            List<BalanceListDto> dtos = (List<BalanceListDto>) response.getData();
//            for (BalanceListDto dto : dtos) {
//
//                // 领取红包
//                if (dto.getType() == 3) {
//                    Packet packet = packetService.selectById(dto.getReferId());
//                    // 判断类型是单聊还是群聊
//
//                    // 发送人
//                    Long packetUserId = packet.getUserId();
//                    User user = userMapper.selectByPrimaryKey(packetUserId);
//                    dto.setPacket(packet);
//                    dto.setSendUserName(user.getNick());
//                    dto.setSendUserId(userId);
//                    // 接收人信息
//                    Long receiveUserId = packet.getReceiveUser();
//                    User receiveUser = userMapper.selectByPrimaryKey(receiveUserId);
//                    dto.setReceiveUserId(receiveUserId);
//                    dto.setReceiveUserName(receiveUser.getNick());
//                }
//            }
//        }
        return response;
    }

    /**
     * 导出表格
     */
    @RequestMapping("exportExcel")
    @ResponseBody
    public void exportExcel(HttpServletRequest request, HttpServletResponse response) throws IOException {

        Long userId = null;
        String userId1 = request.getParameter("userId");
        if (StringUtils.isNotBlank(userId1)) {
            userId = Long.valueOf(userId1);
        }

        Integer status = null;
        String status1 = request.getParameter("status");
        if (StringUtils.isNotBlank(status1)) {
             status = Integer.parseInt(status1);
        }

        String checkTime = request.getParameter("checkTime");
        String recommendCode = request.getParameter("recommendCode");

        Example example = new Example(UserWithdraw.class);
        Example.Criteria criteria = example.createCriteria();
        if (null != status) {
            if (1 == status) {
                criteria.andCondition("(status = 1 or status = 3)");
            }else {
                criteria.andEqualTo("status", status);
            }
        }
        if (null != userId) {
            criteria.andEqualTo("userId", userId);
        }
        if (StringUtils.isNotBlank(checkTime)) {
            criteria.andCondition("DATE_FORMAT(check_time,'%Y-%m-%d') = ", checkTime);
        }
        // 根据创建时间倒序排列
        example.setOrderByClause("ctime desc");


        // 根据邀请码查询
        if (StringUtils.isNotBlank(recommendCode)) {
            criteria.andLike("parentCode", "%" + recommendCode + "%");
        }

        List<UserWithdraw> userWithdrawList = userWithdrawMapper.selectByExample(example);

        List<List<Object>> dataList = new ArrayList<>();
        dataList.add (Arrays.asList ("申请人ID","申请人昵称", "上级邀请码", "提现金额", "姓名", "银行卡号", "开户行","开户行支行", "用户备注",
                "提现备注","审核备注", "状态", "审核时间", "创建时间"));

        List<UserWithdrawExcelDto> list = new ArrayList<>();

//        List<UserWithdraw> userWithdrawList = userWithdrawMapper.selectAll();
        userWithdrawList.stream().forEach(data -> {

            UserWithdrawExcelDto dto = new UserWithdrawExcelDto();
            Long userIdL = data.getUserId();
            dto.setUserId(userIdL);
            dto.setUserNick(data.getUserNick());
            dto.setRecommendCode(data.getParentCode());
            dto.setRealName(data.getCardName());

            // 父级信息
//            String parentUserId = data.getParentUserId();
//            if (StringUtils.isNotBlank(parentUserId)) {
//                dto.setParentUserId(Long.valueOf(parentUserId));
//            }
//            String parentUserNick = data.getParentUserNick();
//            if (StringUtils.isNotBlank(parentUserNick)) {
//                dto.setParentNick(parentUserNick);
//            }
//            String parentPhone = data.getParentPhone();
//            if (StringUtils.isNotBlank(parentPhone)) {
//                dto.setParentMobile(parentPhone);
//            }
            User user = userMapper.queryUserByParam(null, userIdL);
            if (null != user) {
                dto.setUserRemark(user.getRemark());
            }
            String bankNumber = data.getBankNumber();
            dto.setBankNumber(bankNumber);
            dto.setMemo(data.getMemo());
            String rate=Optional.ofNullable(sysDictService.selectOne(DictKey.sys_withdraw_rate)).map(SysDict::getValue).orElse("0");
            BigDecimal money = data.getMoney();
            if (null != money) {
                money =  money.multiply(new BigDecimal("1").subtract(new BigDecimal(rate ).divide(new BigDecimal("100"))));
                money = money.setScale(0, RoundingMode.DOWN).stripTrailingZeros();
                dto.setMoney(money);
            }
            dto.setCheckTime(DateUtils.formatDate(data.getCheckTime(), DateUtils.yyyyMMddHHmmss18));
            dto.setRefuseReason(data.getRefuseReason());

            dto.setBankName(data.getCardBank());
            dto.setChildBankname(data.getCardBankChild());
            dto.setCreateTime(DateUtils.formatDate(data.getCtime(), DateUtils.yyyyMMddHHmmss18));
            Integer statusI = data.getStatus();
            String statusStr = "";
            if (statusI == 0) {
                statusStr = "待审核";
            }else if (statusI == 1 || statusI == 3) {
                statusStr = "审核通过";
            }else if (statusI == 2){
                statusStr = "拒绝";
            }
            dto.setStatus(statusStr);
            list.add(dto);
        });

        //设置响应的编码格式
        response.setCharacterEncoding("UTF-8");
        //设置响应的类型
        response.setContentType("multipart/form-data");
        //设置响应头		filename只能是英文名，中文名下载后文件名会显示异常
        response.setHeader("Content-disposition", "attachment; filename=WithdrawalReview.xlsx");
        try {
            ServletOutputStream outputStream = response.getOutputStream();
            ExcelWriterBuilder writeBook = EasyExcel.write(outputStream, UserWithdrawExcelDto.class);
            ExcelWriterSheetBuilder sheet = writeBook.sheet();
            sheet.doWrite(list);

            outputStream.flush();
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }


}
